package roboticsfmw.sample.sensor;

import roboticsfmw.annotation.HardwareRef;
import roboticsfmw.common.ShutdownEvent;
import roboticsfmw.core.Sensor;
import roboticsfmw.sample.event.WakeEvent;
import roboticsfmw.sample.hardware.UserIOHardwareProxy;


public class KeyboardCommandSensor extends Sensor<UserIOHardwareProxy> {

	@HardwareRef(name = "/hw/userIO")
	public UserIOHardwareProxy userIOhw;

	public KeyboardCommandSensor(String name, long pollInterval, boolean loop) throws IllegalArgumentException {
		super(name, pollInterval, loop);
	}


	@Override
	public void init() {
	}

	@Override
	public void loop(long i) {
		
		String inputCommand = userIOhw.lastCommand;
		if ("robot".equalsIgnoreCase(inputCommand)) {
			WakeEvent we = new WakeEvent();
			getEventBus().notify(we);
		} else if ("shutdown".equalsIgnoreCase(inputCommand)) {
			ShutdownEvent se = new ShutdownEvent("The robot is being shutdown!!!");
			getEventBus().notify(se);
		}
		userIOhw.lastCommand = "";
	
	}

	@Override
	public void shutdown() {
	}

}
